<!-- 时序图 -->
<template>
  <div class="timingDiagram-pack flexs">
    <el-table :data="tableData" style="width: 100%;" height="440" border stripe>
      <el-table-column
        prop="date"
        :label="$i18n.t('workScheduling.line')"
        width="150"
        align="center"
        fixed="left"
      >
        <template slot-scope="{ row }">
          <div class="pack">
            <p class="fontW-600" :title="row.workshopName">
              {{ row.workshopName || "-" }}
            </p>
            <p :title="row.lineName">{{ row.lineName || "-" }}</p>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        prop="name"
        :width="125 * timeData.length"
        class-name="date-pack"
      >
        <template v-slot:header="{ column, $index }">
          <div class="flexs table">
            <div class="th" :key="i" v-for="(ite, i) in timeData">
              {{ ite }}
            </div>
          </div>
        </template>

        <template slot-scope="{ row, $index }">
          <div>
            <div
              class="slider-item"
              :key="`q${$index}${i}`"
              v-for="(ite, i) in row.imgList"
            >
              <el-slider
                v-model="ite.val"
                :show-tooltip="false"
                :id="`id${$index}${i}`"
                range
                class="pack"
                :class="getColor(ite, `id${$index}${i}`)"
                :disabled="true"
                :max="timeData.length"
              ></el-slider>
            </div>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
//例如：import 《组件名称》 from '《组件路径》';
import { getRequirePlanPreList } from "@/api/order/mesRequirePlan.js";
export default {
  name: "",
  //import引入的组件需要注入到对象中才能使用
  components: {},
  props: {
    data: Object,
  },
  data() {
    //这里存放数据
    return {
      setDateList: [],
      timeData: [],
      tableData: [],
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {
    data: {
      handler({ timeData = [], tableData = [] }, old) {
        // console.log(888, timeData, tableData);
        this.setDateList = [];
        this.timeData = timeData;
        tableData.map((item, index) => {
          item.imgList = [];
          (item.orderList || []).map((ite) => {
            let { planBeginDate, planEndDate } = ite;
            let start = this.timeData.findIndex((ite) =>
              planBeginDate.includes(ite)
            );
            let end = this.timeData.findIndex((ite) =>
              planEndDate.includes(ite)
            );
            item.imgList.push({
              val: [Number(start), Number(end + 1)],
              orderStatus: ite.orderStatus,
              qualifiedQty: ite.qualifiedQty,
              actualQuantity: ite.actualQuantity,
              prodName: ite.prodName,
            });
          });
        });
        this.tableData = tableData;
      },
      deep: true,
      immediate: true,
    },
  },
  //方法集合
  methods: {
    getColor(data, id) {
      setTimeout(() => {
        let dom = document.getElementById(id);
        let { actualQuantity, qualifiedQty, prodName } = data;
        let ids = dom.querySelector(".el-slider__bar");
        let str =  `${prodName}(${actualQuantity||0}/${qualifiedQty||0})`
        ids.innerHTML = str;
        ids.title = str;
      }, 1000);
      if (data.orderStatus == 0) {
        return "color1";
      } else if (data.orderStatus == 1) {
        return "color2";
      } else if (data.orderStatus == 3) {
        return "color3";
      } else if (data.orderStatus == 4) {
        return "color4";
      } else {
        return "";
      }
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},

  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style scoped lang="scss">
.timingDiagram-pack {
  width: 100%;
  height: 440px;
  box-sizing: border-box;
  // overflow-y: auto;

  .slider-item {
    margin: 10px 0;
  }
  .table {
    .th {
      // padding: 10px 8px;
      text-align: center;
      // background: #f5f7fa;
      border: 1px solid #ebf0f5;
      cursor: pointer;
      color: #666;
      // font-size: 14px;
      width: 125px;
      display: flex;

      align-items: center;
      justify-content: center;
      border-right: 1px solid #dedede;
    }
  }

  /deep/.cell {
    // font-size: 14px;
  }

  .title {
    width: 150px !important;
  }
  .pack {
    font-size: 14px;
    color: #333;
    // height: 96px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    // padding: 0px 10px;
    // border: 1px solid #ebf0f5;
    border-top: 0px;
    // margin-bottom: 16px;
    p {
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      width: 100%;
      flex-shrink: 0;
      // font-size: 14px;
    }
  }

  // .right {
  //   // border: 1px solid #ebf0f5;
  //   box-sizing: border-box;
  //   width: calc(100% - 150px);
  //   margin: 0 20px;
  //   // overflow-x: auto;
  //   // overflow: auto;
  /deep/.el-table--enable-row-hover {
    .el-table__body tr:hover > td {
      background-color: red !important;
      /* color: #fff; */
    }
  }
  /deep/.el-slider__runway {
    height: 35px;
    border-radius: 35px;
  }
  /deep/.el-slider__bar {
    height: 35px;
    border-radius: 35px;
    background-color: #3b82f680;
    text-align: center;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .el-drawer__content {
    padding: 0px;
  }
  .el-tooltip__popper {
    left: 20%;
    top: 10px;
  }
  /deep/.el-slider__button-wrapper {
    top: 5px;
    z-index: 1;
    display: none !important;
  }
  /deep/.el-slider__runway {
    margin: 0px !important;
    background-color: transparent;
  }

  .color1 {
    /deep/.el-slider__bar {
      background-color: rgba(239, 226, 247, 0.5);
      border: 2px solid #f34a30;
    }
  }
  .color2 {
    /deep/.el-slider__bar {
      background-color: rgba(222, 242, 255, 0.5);
      border: 2px solid #eebf27;
    }
  }
  .color3 {
    /deep/.el-slider__bar {
      background-color: rgba(177, 207, 250, 0.39);
      border: 2px solid #3d82ea;
    }
  }
  .color4 {
    /deep/.el-slider__bar {
      background-color: #18c9274f;
      border: 2px solid #18c927;
    }
  }
  /deep/.date-pack {
    padding: 0px !important;
    .th {
      height: 40px;
    }
  }
}
// }
.flexs {
  display: flex;
}
.height-90 {
  height: 45px;
}
.fontW-600 {
  font-weight: 600;
}
.width-100 {
  width: 100%;
}
</style>
